//
//  ViewController.m
//  GTQCitySelector
//
//  Created by 光头强 on 16/7/20.
//  Copyright © 2016年 Ls. All rights reserved.
//

#import "ViewController.h"
#import "GTQSelectCityViewController.h"
#import "LeftTextRightImageButton.h"

@interface ViewController ()<GTQSelectCityViewControllerDelegate>
/** 按钮 */
@property (nonatomic, strong) LeftTextRightImageButton *leftBarButton;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"首页";
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupNavigationItem];
}

- (void)setupNavigationItem {
    [self.navigationController.navigationBar setBarTintColor:[UIColor grayColor]];
    
    self.leftBarButton = [LeftTextRightImageButton buttonWithType:UIButtonTypeCustom];
    [self.leftBarButton setTitle:@"深圳" forState:UIControlStateNormal];
    [self.leftBarButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.leftBarButton setImage:[UIImage imageNamed:@"arr2"] forState:UIControlStateNormal];
    [self.leftBarButton addTarget:self action:@selector(leftBarButtonBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.leftBarButton setFrame:CGRectMake(0, 0, 42, 30)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.leftBarButton];
}

- (void)leftBarButtonBtnClick:(UIButton *)sender {
    GTQSelectCityViewController *selectVC = [[GTQSelectCityViewController alloc] init];
    selectVC.delegate = self;
    UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:selectVC];
    [self.navigationController presentViewController:navc animated:YES completion:nil];
}

- (void)didSelectedTitle:(NSString *)title {
    [self.leftBarButton setTitle:title forState:UIControlStateNormal];
}

@end
